# -*- coding: utf-8 -*-
# @Time : 2021/9/13 12:56
# @Author : 伟哥
# @Email : xw@gmail.com
# @File : table.py
# @Project : crm
'''工具根据表格，输入列来查找该列的元素对象'''

from selenium.webdriver.common.by import By
def table(driver,table,num,tet,cell):
    '''
    根据输入的表格元素对象，表格的页数，判断依据，列数，找到元素对象
    :param driver: 浏览器
    :param table: 表格对象
    :param num: 页数
    :param tet: 判断对象
    :param cell: 行数
    :return:
    '''


    table = driver.find_element(*table)
    tr_locator=(By.TAG_NAME,"tr")
    td_locator=(By.TAG_NAME,"td")
    xiayiye_locator = (By.LINK_TEXT, "下一页 »")
    input_locator=(By.TAG_NAME,"input")
    a=1
    for i in range(num):
        trs = table.find_elements(*tr_locator)
        for tr in trs:
            tds = tr.find_elements(*td_locator)
            if isinstance(tet,str) and tet in tds[cell].text:
                a=2
                tds[0].find_element(*input_locator).click()
                break
            elif isinstance(tet,int) and len(tds[cell].text)==tet:
                a=2
                tds[0].find_element(*input_locator).click()
                break
        else:
            driver.find_element(*xiayiye_locator).click()
        if a==2:
            break